package com.dao.impl;

import com.bean.HwStu;
import com.bean.HwStuAttach;
import com.dao.BaseDao;
import com.dao.HwStuAttachDao;
import com.utils.SqlUtils;
import org.junit.Test;

import java.util.List;
import java.util.Map;

public class HwStuAttachDaoImpl extends BaseDao implements HwStuAttachDao {
    String[] strings = {"HwStuName"};
    @Override
    public List<HwStuAttach> selectForPageItems(int begin, int pageSize, String content) {
        if (content == null) {
            content = "";
        }
        content = "%" + content + "%";

        String sql = SqlUtils.pageSql(HwStuAttach.class,HwStu.class, strings);
        return queryForList(HwStuAttach.class, sql, content, begin, pageSize);
    }

    @Override
    public Integer selectForPageTotalCount(String content) {
        if (content == null) {
            content = "";
        }
        content = "%" + content + "%";
        String sql = SqlUtils.countSql(HwStuAttach.class,HwStu.class,strings);
        Number count = (Number) queryForSingleValue(sql, content);
        return count.intValue();
    }

    @Override
    public HwStuAttach selectBy(HwStuAttach hwStuAttach) {
        Map.Entry<String, Object[]> entry = SqlUtils.selectBy(hwStuAttach, HwStu.class, strings);
        return queryForOne(HwStuAttach.class, entry.getKey(),entry.getValue());
    }

    @Override
    public int insert(HwStuAttach hwStuAttach) {
        Map.Entry<String, Object[]> entry = SqlUtils.insertSql(hwStuAttach, strings);
        return update(entry.getKey(), entry.getValue());
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        String sql = "delete from `hwStuAttach` where `id` = ?";
        return update(sql, id);
    }

    @Override
    public int updateByPrimaryKey(HwStuAttach hwStuAttach) {
        Map.Entry<String, Object[]> entry = SqlUtils.updateSql(hwStuAttach, strings);
        return update(entry.getKey(),entry.getValue());
    }

    @Override
    public int deleteByHwStuId(Integer hwStuId) {
        String sql = "delete from `hwStuAttach` where `hwStuId` = ?";
        return update(sql, hwStuId);
    }
}
